import Mock from 'mockjs'
import {param2Obj} from '../utils'

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    gtTimeStr: '@datetime',
    wfNo: "201901124393a5",
    provinceId: '@integer(300, 5000)',
    provinceName: "广东省",
    cityId: '@integer(300, 5000)',
    cityName: "广州市",
    blockId: '@integer(300, 5000)',
    blockName: '海珠区',
    'wfFuncType|+1': [1,2],
    'wfFuncTypeName|+1': ['违停', '其他类型'],
    imei: '@integer(1000000000, 50000000000)',
    deviceHphm: "警A@integer(10000, 90000)",
    wfId: null,
    'shStatus|1': [1,2,3,4],
    'jgDataStatus|1': [1,2,3,4]
  }))
}

export default {
  query: config => {
    const {provId, cityId, blockId, wfType, imei, zfHphm, gtStartDate, gtEndDate, pageIndex, pageSize, sort} = JSON.parse(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false
      // if (type && item.type !== type) return false
      // if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }
    console.log('pageSize * pageIndex',pageSize * pageIndex,pageSize,pageIndex)

    const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))

    return {
      result: true,
      data: {
        totalSize: mockList.length,
        content: pageList
      }
    }
  },
  getPv: () => ({
    pvData: [{key: 'PC', pv: 1024}, {key: 'mobile', pv: 1024}, {key: 'ios', pv: 1024}, {key: 'android', pv: 1024}]
  }),
  getArticle: (config) => {
    const {id} = param2Obj(config.url)
    for (const article of List) {
      if (article.id === +id) {
        return article
      }
    }
  },
  createArticle: () => ({
    data: 'success'
  }),
  updateArticle: () => ({
    data: 'success'
  })
}
